const { defineConfig } = require('@vue/cli-service')
const port = process.env.port || process.env.npm_config_port || 9529 
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave:false,
  css: {
    loaderOptions: {
      less: {
        // 新增全局变量
        additionalData: `@import "~@/assets/styles/vant-cover.less";`,
        lessOptions: {
          // 现在 modifyVars 需要放在这里
          modifyVars: {
            hack: `true; @import "~@/assets/styles/vant-cover.less";`
          }
        }
      }
    }
  },
  devServer: {
    port: port,
    open: false,
    client: {
      overlay: false
    },
    proxy: {
      '/api': {
        target: process.env.VUE_APP_BASE_API,
        changeOrigin: true,
        pathRewrite: {
          '^/api': '/api' // 保持路径不变
        }
      }
    }
  },

  configureWebpack: config => {
    // 测试环境开启断点调试
    if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
      config.devtool = 'source-map'
    }
  },
  

  // chainWebpack: config => {
  //   config.optimization.minimizer('terser').tap((args) => {
  //     args[0].terserOptions.compress.drop_console = true
  //     return args
  //   })
  // }
  // 刨除console.log
  chainWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      config.optimization.minimizer('terser').tap((args) => {
        args[0].terserOptions = {
          compress: {
            warnings: false,
            drop_console: true,
            drop_debugger: true,
            pure_funcs: ['console.log']
          }
        }
        return args
      })
    }
  }
})
